#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# File Name   : p2.py
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Sat 2023-10-14 14:22:27(+0800)

"""

Usage:

"""

import sqlite3

from rich import print

profiles = {}
with open("/tmp/f5") as f:
    for line in f:
        adjustments = line.strip().split()
        profiles[adjustments[0]] = adjustments[1:]

active_freq = {}
with open("/tmp/f3") as f:
    for line in f:
        adjustments = line.strip().split()
        active_freq[adjustments[0]] = adjustments[1]

adjustments = {
    "A-184-M3-Torpedo-U": "30000",
    "uuv-sm": "45000",
    "A-184-Mod3": "30000",
    "A-184-Torp": "32000",
    "A-184-Torpedo-U": "32000",
    "AI-AT-1-Torpedo": "20450",
    "APR-2E-Torp": "20650",
    "APR-2E-Torp-User": "20650",
    "APR-3E": "20650",
    "APR-3E-TorpUser": "20650",
    "Arihant-SSBN-B": "3400",
    "Arleigh-Burke-FLT-2": "3000",
    "Black-Shark-Torp": "31000",
    "Black-Shark-Torp-U": "31000",
    "Borey-SSBN-B": "2700",
    "C.F.Adams": "4500",
    "Cavour-CVH": "18000",
    "Daphne-SS-ZA": "2800",
    "E45-75A-Torpedo": "20000",
    "Forrest-Sherman-DD": "4500",
    "Foxtrot-SS": "18500",
    "Hercules-DDG": "3000",
    "Jianghu-II-FFGHM": "3850",
    "Jiangwei-II-FFGHM": "3850",
    "Kang-Ding-FFG": "1250",
    "Kang-Kyeong-MHSC": "13000",
    "Kilo-Imp-KLUB-SS-CH": "3400",
    "Kilo-Improved-SS-CH": "3400",
    "Kilo-Improved-SSK": "3400",
    "Kilo-KLUB-SS-IND": "3400",
    "Kilo-KLUBimp-SS-ALG": "3400",
    "Kilo-KLUBimp-SS-IND": "3400",
    "Kilo-KLUBimp-VT": "3400",
    "Kilo-SS-ALROSa": "3400",
    "Kilo-SS-CHI": "3400",
    "Kilo-SS-IND": "3400",
    "Kilo-SS-IRN": "3400",
    "Kilo-SS-PL": "3400",
    "Kilo-SSK": "3400",
    "Kirov-CGN": "1200",
    "Krivak-III-WFF": "3785",
    "Krupnyy-DDG": "2850",
    "Kuznetsov-CV": "3900",
    "L5-Torp": "32000",
    "L5-Torpedo-U": "32000",
    "LA-SSN": "2500",
    "LA-SSN-VLS": "2500",
    "Leander-FFH-CL": "4000",
    "MU-90-Torpedo": "21000",
    "MU-90-Torpedo-User": "21000",
    "Mk-37-Torpedo-Mod-0": "20350",
    "Mk-37-Torpedo-Mod-1": "20350",
    "Mk-37C": "20350",
    "Mk-37C-Torpedo": "20350",
    "Mk-44-Torp": "20300",
    "Mk-44-Torpedo-User": "20300",
    "Mk-46-Torpedo": "20450",
    "Mk-46-Torpedo-U": "20450",
    "Mk-48-ADCAP-Torp": "20000",
    "Mk-48-ADCAP-Torpedo": "20000",
    "Mk-48-Mod-1-Torp-U": "20000",
    "Mk-48-Mod-4": "20000",
    "Mk-48-Mod-4-Topredo": "20000",
    "Mk-50": "20550",
    "Mk-50-Torp-User": "20550",
    "Mk-54": "23000",
    "Mk-54-Torp-User": "23000",
    "Parchim-I-FS": "7500",
    "Perth-DDG": "4500",
    "Romeo-Imp-SSK-EG": "2800",
    "Romeo-SSK-KP": "3100",
    "Romeo-SSK-RU": "3100",
    "SH-60B-Sea-Hawk": "10300",
    "SH-60B-Sea-Hawk-Gen": "10300",
    "SH-60F-Sea-Hawk": "10300",
    "SST-4-Torpedo": "21400",
    "SUT-Torpedo": "20350",
    "Sauro-SS-Batch-I": "2900",
    "Sauro-SS-Batch-II": "2900",
    "Sauro-SS-Batch-III": "2850",
    "Sauro-SS-Batch-IV": "2850",
    "TEST-71M-Torpedo": "19750",
    "TEST-71ME-AI": "19750",
    "TEST-71ME-NK-Torp": "19750",
    "TEST-71ME-Torpedo": "19750",
    "TYPE-207-Mod-SS-DN": "2920",
    "TYPE-207-Mod-SS-PL": "2920",
    "TYPE-207-SS": "2800",
    "Trenchant-SSN-Trf": "2700",
    "Type-89-Topredo-U": "20700",
    "Type-89-Torp": "20700",
    "TYPE-209/1100-SS": "2920",
    "TYPE-209/1200-SS-AR": "2400",
    "TYPE-209/1200-SS-CO": "2400",
    "TYPE-209/1200-SS-GR": "2400",
    "TYPE-209/1200-SS-KR": "2800",
    "TYPE-209/1200-SS-PE": "2400",
    "TYPE-209/1200-SS-TR": "2400",
    "TYPE-209/1300-SS-EQ": "2400",
    "TYPE-209/1300-SS-ID": "2400",
    "TYPE-209/1300-SS-VN": "2400",
    "TYPE-209/1400-M-SS": "2800",
    "TYPE-209/1400-MOD.3": "2800",
    "TYPE-209/1400-SS-CL": "2400",
    "TYPE-209/1400-SS-TR": "2800",
    "TYPE-209/1500-SSK": "2800",
    "TYPE-209PN/AIP-SSK": "2800",
    "TYPE-210-SS": "2800",
    "TYPE-214-SS": "2940",
    "TYPE-800-SS": "2900",
    "Type-052D-DDGHM": "3785",
    "Type-40-Torpedo": "20400",
    "Type-431-Torpedo": "22000",
    "Type-613-Torpedo": "22000",
    "Typhoon-Impr": "3500",
    "UGST-Torpedo": "19500",
    "UMGT-1": "20000",
    "UMGT-1-Torp-User": "20000",
    "USET-80-Torp": "20500",
    "USET-80-Torpedo": "20500",
    "USET-80K-TorpUser": "20500",
    "Wadi-MRagh-PGG": "13000",
    "YU-3-Torp-User": "19350",
}

active_freq = active_freq | adjustments

for k in profiles.keys():
    if k in active_freq:
        profiles[k].append(active_freq[k])
    else:
        profiles[k].append(0)

aircraft_or_unkown = {
    "Z-18F-H": "10550",
    "Z-8-Super-Frelon-H": "10550",
    "Z-9A-Haitun-H": "10550",
    "A-109M-Agusta-H": "10300",
    "Cortenair-FFG": "2865",
    "AB.212-Agusta-H": "10520",
    "AS-321-Super-Frelon-H": "10520",
    "AS-321G-Super-Frelon-H": "10520",
    "AS-322F-Super-Puma-H": "10520",
    "AS-365-Dauphin-H": "10520",
    "ASH-3-Sea-King-H": "10520",
    "ASH-3D-Sea-King-H": "10400",
    "ASH-3H-Sea-King-H": "10400",
    "Actuv3": "5000",
    "Actuv5": "5000",
    "Benjamin-Franklin-SSBN": "17500",
    "Boeing-107-H": "10300",
    "CH-124-Sea-King-H": "10400",
    "Cahrlie-II-SSGN": "3600",
    "DM2-A3": "22000",
    "DM2-A4": "22000",
    "EH-101-Merlin-H": "10350",
    "F17-Torp.": "17000",
    "Fatahilan-FFG": "3050",
    "Forragut-DDG": "4500",
    "Gazantep-FFG": "7500",
    "HAS-50-Sea-King-H": "10400",
    "KA-25A-Hormone-H": "10600",
    "KA-27-Helix-H": "10450",
    "KA-28-Helix-H": "10450",
    "Lida-II-DDG": "2850",
    "Lynx-Mk-4-H": "10520",
    "Lynx-Mk-88-H": "10300",
    "Lynx-Mk-90B-H": "10300",
    "MGK-608E-Stationar-Sonar": "8500",
    "MH-60R-Sea-Hawk-H": "10100",
    "Medvedka-PT": "15000",
    "Meko-200-FF": "2950",
    "Mine-Hunt-Helo-EH-101": "55000",
    "Mine-Hunt-Helo-MH-53D": "45000",
    "Mine-Hunt-Helo-MH-53E": "50000",
    "Mine-Hunt-Helo-MI-14": "40000",
    "Mobile-Decoy": "4000",
    "NFH-90-H": "10200",
    "Pr.20380-mod.1-FFGH": "3550",
    "Pr.22350": "1200",
    "S-70-Sea-Hawk-H": "10400",
    "S-70-Thunderhawk-H": "10300",
    "S-70C-Thunderhawk-H": "10400",
    "SAET-40": "20450",
    "SH-2G-H": "10570",
    "SH-2H-H": "10570",
    "SH-3-Sea-King-H": "10400",
    "SH-3H-Sea-King-H": "10400",
    "SH-60B-Sea-King-H": "10400",
    "Sea-King-HAS-5/6-H": "10500",
    "Sea-King-MK-41-H": "10300",
    "Sea-King-Mk-42-H": "10520",
    "Sonobuoy-NATO-AI": "10000",
    "Sonobuoy-Rus-AI": "8000",
    "Sovremennuy-II": "1200",
    "Spearfish-Attack-Mode": "33000",
    "Ticonderoga-CG": "3000",
    "Ticonderoga-CG-VLS": "3000",
    "UUV": "45000",
    "Vasca-da-Gama-FFH": "2875",
}


connection = sqlite3.connect("/tmp/db.sqlite3")

cursor = connection.cursor()

cursor.execute("delete from app02_sonarprofile")
connection.commit()

index = 1
for key, item in profiles.items():
    t1 = [index, key] + [int(i) for i in item]
    print(f"INSERT INTO app02_sonarprofile VALUES {tuple(t1)}")
    cursor.execute(f"INSERT INTO app02_sonarprofile VALUES {tuple(t1)}")
    index = index + 1

for key, item in aircraft_or_unkown.items():
    name = "unknown_or_aircraft " + key
    t1 = [index, name] + [0, 0, 0, 0, 0, 0, 0, int(item)]
    print(f"INSERT INTO app02_sonarprofile VALUES {tuple(t1)}")
    cursor.execute(f"INSERT INTO app02_sonarprofile VALUES {tuple(t1)}")
    index = index + 1

connection.commit()

print(connection.total_changes)
